/*******************************************************************************
 * Copyright (c) 2006 CEA List.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     CEA List - initial API and implementation
 *******************************************************************************/
package com.cea.papyrus.diagram.statemachine.helper;

import org.eclipse.uml2.uml.PseudostateKind;

import com.cea.papyrus.core.IPapyrusUIConstants;
import com.cea.papyrus.core.helper.DefaultModelerHelper;
import com.cea.papyrus.core.helper.GraphEdgeHelper;
import com.cea.papyrus.core.helper.NodeHelper;
import com.cea.papyrus.diagram.classdiagram.helper.EdgeGraphLinkHelper;
import com.cea.papyrus.diagram.classdiagram.helper.NodeCommentHelper;
import com.cea.papyrus.diagram.classdiagram.helper.NodeConstraintHelper;


/**
 * Manages state machine diagrams.
 * 
 * @author David Servat
 * @since 29 jan. 07
 */
public class StateMachineDiagramModelerHelper extends DefaultModelerHelper{

	/**
	 * The EINSTANCE.
	 */
	private static StateMachineDiagramModelerHelper EINSTANCE; 

	/**
	 * Returns the unique instance (Singleton pattern).
	 * 
	 * @return this instance of Helper
	 */
	public static StateMachineDiagramModelerHelper getInstance(){
		if(EINSTANCE == null)
			EINSTANCE = new StateMachineDiagramModelerHelper();
		return EINSTANCE;
	}

	/**
	 * The channel.
	 */
	private int channel = 501;

	/**
	 * The element types.
	 */
	protected final Class elementTypes[] = {
			org.eclipse.uml2.uml.Element.class,
			org.eclipse.uml2.uml.Comment.class,
			org.eclipse.uml2.uml.Constraint.class,

			org.eclipse.uml2.uml.ConnectionPointReference.class,
			org.eclipse.uml2.uml.FinalState.class,
//			org.eclipse.uml2.uml.ProtocolStateMachine.class,

			org.eclipse.uml2.uml.Pseudostate.class,

			com.cea.papyrus.diagram.statemachine.pseudoelement.Choice.class,
			com.cea.papyrus.diagram.statemachine.pseudoelement.DeepHistory.class,
			com.cea.papyrus.diagram.statemachine.pseudoelement.EntryPoint.class,
			com.cea.papyrus.diagram.statemachine.pseudoelement.ExitPoint.class,
			com.cea.papyrus.diagram.statemachine.pseudoelement.Fork.class,
			com.cea.papyrus.diagram.statemachine.pseudoelement.Initial.class,
			com.cea.papyrus.diagram.statemachine.pseudoelement.Join.class,
			com.cea.papyrus.diagram.statemachine.pseudoelement.Junction.class,
			com.cea.papyrus.diagram.statemachine.pseudoelement.ShallowHistory.class,
			com.cea.papyrus.diagram.statemachine.pseudoelement.Terminate.class,
			
			org.eclipse.uml2.uml.Region.class,

			org.eclipse.uml2.uml.State.class,
			org.eclipse.uml2.uml.StateMachine.class,
			
			org.eclipse.uml2.uml.Trigger.class,
			
			org.eclipse.uml2.uml.AnyReceiveEvent.class,
			org.eclipse.uml2.uml.CallEvent.class,
			org.eclipse.uml2.uml.ChangeEvent.class,
			org.eclipse.uml2.uml.SignalEvent.class,
			org.eclipse.uml2.uml.TimeEvent.class
			
	};

	/**
	 * The node helpers.
	 */
	protected final NodeHelper nodeHelper[] = {
			new NodeHelper(),
			new NodeCommentHelper(),
			new NodeConstraintHelper(),

			new NodeConnectionPointReferenceHelper(),
			new NodeFinalStateHelper(),
//			new NodeStateMachineHelper(),

			new NodePseudostateHelper(),

			new NodePseudostateHelper(PseudostateKind.CHOICE_LITERAL),
			new NodePseudostateHelper(PseudostateKind.DEEP_HISTORY_LITERAL),
			new NodePointHelper(PseudostateKind.ENTRY_POINT_LITERAL),
			new NodePointHelper(PseudostateKind.EXIT_POINT_LITERAL),
			new NodePseudostateHelper(PseudostateKind.FORK_LITERAL),
			new NodePseudostateHelper(PseudostateKind.INITIAL_LITERAL),
			new NodePseudostateHelper(PseudostateKind.JOIN_LITERAL),
			new NodePseudostateHelper(PseudostateKind.JUNCTION_LITERAL),
			new NodePseudostateHelper(PseudostateKind.SHALLOW_HISTORY_LITERAL),
			new NodePseudostateHelper(PseudostateKind.TERMINATE_LITERAL),
			
			new NodeRegionHelper(),

			new NodeStateHelper(),
			new NodeStateMachineHelper(),
			
			new NodeTriggerHelper(),
			
			new NodeAnyReceiveEventHelper(),
			new NodeCallEventHelper(),
			new NodeChangeEventHelper(),
			new NodeSignalEventHelper(),
			new NodeTimeEventHelper()
	};

	/**
	 * The edge types.
	 */
	protected final Class edgeTypes[] = {
			com.cea.papyrus.core.pseudoelement.GraphicalLink.class,
			org.eclipse.uml2.uml.Transition.class,

//			org.eclipse.uml2.uml.ProtocolConformance.class,
//			org.eclipse.uml2.uml.ProtocolTransition.class,

	};

	/**
	 * The edge helpers.
	 */
	protected final GraphEdgeHelper edgeHelper[] = {
			new EdgeGraphLinkHelper(),
			new EdgeTransitionHelper(),

//			new GraphEdgeHelper(),
//			new GraphEdgeHelper(),

	};


	/**
	 * Create the helpers for model elements.
	 */
	public StateMachineDiagramModelerHelper() {
		for(int i=0; i<elementTypes.length; i++)
			creationFactoryMap.put( elementTypes[i], nodeHelper[i]);
		for(int i=0; i<edgeTypes.length; i++)
			creationFactoryMap.put( edgeTypes[i], edgeHelper[i]);
	}

	/**
	 * Gets the id.
	 * 
	 * @return the id
	 */
	public String getId() {
		return IPapyrusUIConstants.STATE_MACHINE_DIAGRAM;
	}

}
